﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using WebMatrix.WebData;
using z.Filters;

namespace z.App_Start {
	[InitializeSimpleMembership]
	public class ZStart {
		public static void CreateDatabase() {
			Database.SetInitializer<m.db.Database>(null);
			try {
				using (var db = new m.db.Database()) {
					if (!db.Database.Exists()) {
						db.Database.Create();
						WebSecurity.CreateAccount("Admin", "123123");
						var r = new m.db.webpages_Roles();
						r.UserProfiles.Add(db.UserProfiles.Find(1));
						db.webpages_Roles.Add(r);
					}
				}
			} catch (Exception ex) {
				throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
			}
		}
	}
}